package projectManagementServer;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ConfirmationGUI extends JPanel implements ActionListener{
	JFrame f;

	public ConfirmationGUI(String msg) {
		setPreferredSize(new Dimension(227, 134));
		setLayout(null);
		
		JLabel lblConfirmAction = new JLabel("Confirm "+msg);
		lblConfirmAction.setFont(new Font("Calibri", Font.PLAIN, 18));
		lblConfirmAction.setHorizontalAlignment(SwingConstants.CENTER);
		lblConfirmAction.setBounds(20, 30, 177, 40);
		add(lblConfirmAction);
		
		JButton btnOk = new JButton("OK");
		btnOk.setActionCommand(msg);
		btnOk.setBounds(20, 78, 89, 40);
		btnOk.putClientProperty("Quaqua.Button.style", "bevel");
		btnOk.addActionListener(this);
		add(btnOk);
		
		JButton btnCancel = new JButton("CANCEL");
		btnCancel.setBounds(119, 78, 89, 40);
		btnCancel.putClientProperty("Quaqua.Button.style", "bevel");
		btnCancel.addActionListener(this);
		add(btnCancel);
		
		f = new JFrame();
		f.add(this);
		f.setResizable(false);
		f.setVisible(true);
		f.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		f.pack();
		f.setLocationRelativeTo(null);
	}

	@Override
	public void actionPerformed(ActionEvent btn) {
		String cmd = btn.getActionCommand();
		
		if(cmd.equalsIgnoreCase("DELETE")){
			try {
				ServerGUI.respondDeleteProj();
			} catch (Exception e) {
				e.printStackTrace();
			}
			f.setVisible(false);
		}
		
		if(cmd.equalsIgnoreCase("UPDATE USER")){
			try {
				ServerGUI.respondDeleteUser();
			} catch (Exception e) {
				e.printStackTrace();
			}
			f.setVisible(false);
		}
		
		if(cmd.equalsIgnoreCase("Cancel")){
			f.setVisible(false);
		}
		
	}

}
